home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 3_0 / CUTILSLI / UTILITYL / ATOI.C next >
Text File  |  1987-11-10  |  1KB  |  47 lines

  1.     /**********************************************
  2.     *    Filename:    atoi.c                                                                 
  3.     *    Purpose:    Atoi Function                      
  4.     *    Authors:    Robert E. Neville                                                       
  5.     *    Date:        November 10, 1987                                                        
  6.     *    Functions:     atoi().
  7.     *    Version:    1.0                                                                            
  8.     *    Copyright:   ⌐ 1987     Hummingbird Graphics                                  
  9.     ***********************************************/
  10.  
  11.     #include <MacTypes.h>
  12.     #include <Strings.h>
  13.     #include <Pascal.h>
  14.  
  15.     /* Macro */
  16.  
  17.     #define isspace(c)    (c== ' ' || c == '\t')
  18.     #define ZERO        48
  19.  
  20.     /*************************************************
  21.     *    Function:    atoi( string )
  22.     *    Purpose:    Convert ASCII string to an Integer
  23.     *    Passed:        string - Register Char *
  24.     *    Returned:    answer - Long converted to int
  25.     **************************************************/
  26.  
  27.     atoi(string)
  28.     register char    *string;
  29.     {
  30.         register long    answer = 0L;
  31.         Boolean            negative = FALSE;
  32.     
  33.         while ( isspace(*string) )
  34.             string++;
  35.         if ( *string == '-' )
  36.             negative = TRUE;
  37.         while ( *string )
  38.         {
  39.             answer = (answer * 10) + (*string - ZERO);
  40.             string++;
  41.         }
  42.         if ( negative )
  43.             answer = 0 - answer;
  44.         return (int)answer;
  45.     }
  46.     
  47.     /**********        End of File     **********/